<!-- 供应商详情 - 综合表单页面 -->
<template>
    <div class="page-container">
        <el-form ref="form" :model="form" :label-width="$globalCss.formLabelWidth_default" :rules="formRules"
            v-loading="loading" label-position="right" class="common-form-row">

            <ex_header_spiler :title="$tt('label_base_info')"></ex_header_spiler>

            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_code')" prop="supplierCode" class=" ">
                        <ex_super_input v-model="form.supplierCode" class="w_fill" maxlength="20" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_name')" prop="supplierName" class=" ">
                        <ex_super_input v-model="form.supplierName" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_type')" prop="supplierType" class=" ">
                        <ex_super_input v-model="form.supplierType" class="w_fill" type="select"
                            enum="SrmSupplierTypeEnum" />
                    </el-form-item>
                </el-col>
            </el-row>



            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_comp_name')" prop="companyName" class=" ">
                        <ex_super_input v-model="form.companyName" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_tax_no')" prop="dutyParagraph" class=" ">
                        <ex_super_input v-model="form.dutyParagraph" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_opening_bank')" prop="depositBank" class=" ">
                        <ex_super_input v-model="form.depositBank" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_account_name')" prop="openAccountName" class=" ">
                        <ex_super_input v-model="form.openAccountName" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_bank_account')" prop="bankAccount" class=" ">
                        <ex_super_input v-model="form.bankAccount" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
            </el-row>

            <ex_header_spiler :title="$tt('label_srm_supplier_contact_info')"></ex_header_spiler>

            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_contact_name')" prop="contactName" class=" ">
                        <ex_super_input v-model="form.contactName" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_position')" prop="position" class=" ">
                        <ex_super_input v-model="form.position" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_contact_phone')" prop="contactPhone" class=" ">
                        <ex_super_input v-model="form.contactPhone" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_email')" prop="contactEmail" class=" ">
                        <ex_super_input v-model="form.contactEmail" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_contact_address')" prop="address" class=" ">
                        <ex_super_input v-model="form.address" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_srm_supplier_url')" prop="companyWebsite" class=" ">
                        <ex_super_input v-model="form.companyWebsite" class="w_fill" maxlength="50" show-word-limit />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item>
                <span>
                    <el-button type="primary" @click="submit">{{ $tt('label_save') }}</el-button>
                    <el-button @click="return_page_back()">{{ $tt('label_fms_account_config_cancel') }}</el-button>
                </span>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>

import router_params from '@/mixin/router_params';

let defaultObj = {
    supplierCode: null,
    supplierName: null,// 	供应商名称
    supplierType: '',// 	供应商类型：FIRST_PASS=头程供应商，OVERSEA_LOCATION=存储仓
    sort: null,// 	类别：EXTERNAL_MATCHING=外配同行，TRUNK_MOVEMENT=干线运输,
    status: 'E',// 	状态：E=激活,D=禁用
    apiServiceId: null,//	api服务ID：0=无需API服务
    apiServiceCode: null,// 	API服务代码
    insuranceId: null,//	保险服务ID：0=无需保险服务
    insuranceCode: null,// 	保险服务代码
    personUserId: null,// 	开发人ID
    settlementType: 'IMMEDIATE',// 	结算类型：IMMEDIATE=现结，MONTHLY=月结，PREIMBURSE=预付
    currencyCode: null,// 	结算币种
    companyName: null,// 	公司名称
    dutyParagraph: null,// 	税号
    depositBank: null,// 	开户行
    openAccountName: null,// 	开户名称
    bankAccount: null,// 	银行账号
    contactName: null,// 	联系人名称
    position: null,// 	职位
    contactPhone: null,// 	联系人电话
    contactEmail: null,// 	联系人邮箱
    address: null,// 	联系人地址
    companyWebsite: null,// 	公司网址
    notes: null,// 	备注
}
export default {

    mixins: [router_params],
    components: {},

    data() {
        return {
            edit: false,
            loading: false,
            form: _.cloneDeep(defaultObj),
            formRules: {
                supplierCode: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' },
                supplierName: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' },
                companyName: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' },
            },
        };
    },

    methods: {
        isSetCurrentUser(list) {
            if (this.edit) return
            let user = this.$loginUser
            if (user) {
                if (list.some(it => it.userId == user.userId)) {
                    this.form.personUserId = user.userId
                }
            }

        },
        init_data_default(into_params) {
            this.edit = !!into_params.edit
            if (this.edit) {
                if (into_params.id) {
                    this.loading = true
                    this.$ajax({
                        url: "/srm-api/supplier/SupplierRpc/detail.json",
                        method: 'post',
                        data: { id: into_params.id },
                        success: (res) => {
                            this.loading = false
                            this.form = Object.assign({}, _.cloneDeep(defaultObj), res.data)
                            this.$emit("tagModifyLabel", { _key: 'label_name_code', name: this.$tt("label_edit_supply"), code: res.data.supplierName })


                        }
                    })
                }
                this.$emit("tagModifyLabel", "label_edit_supply")
            } else {
                this.$emit("tagModifyLabel", "label_new_supply")
            }
        },
        categChange(v) {
            if (this.$refs.categCascader) {
                let item = _.head(this.$refs.categCascader.getCheckedNodes())
                if (item) {
                    let { pathNodes } = item
                    pathNodes.forEach((it, index) => {
                        this.form['categId' + index] = it.data.id
                        this.form['categName' + index] = it.data.igName
                        this.form['categNameEn' + index] = it.data.igNameEn
                    })
                }
            }

        },
        submit() {
            this.$refs['form'].validate((valid, obj) => {

                if (valid) {
                    this.$ajax({
                        url: "/srm-api/supplier/SupplierRpc/saveUpdate.json",
                        method: 'post', type: 'json',
                        data: this.form,
                        success: (res) => {
                            this.$message.success(this.$tt('tip_submit_success'))
                            this.$refreshStoreCommonDataGroup('/srm-api/supplier/SupplierRpc/getSupplierDict.json')

                            this.return_emit(null, "reload")
                            this.return_page_back()


                        }
                    })
                } else {
                    this.$message.error(this.$tt('form_validate_error'))
                    return false;
                }
            });

        },
    }
};

</script>
<style></style>
